package com.evenmo.hrms.service.serviceImpl;

import com.evenmo.hrms.mapper.oldmapper.*;
import com.evenmo.hrms.pojo.*;
import com.evenmo.hrms.service.HrmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
@Service("hrmsService")
public class HrmsServiceImpl implements HrmsService {
    @Autowired
    UserMapper userMapper;
    @Autowired
    DeptMapper deptMapper;
    @Autowired
    JobMapper jobMapper;
    @Autowired
    NoticeMapper noticeMapper;
    @Autowired
    DocumentMapper documentMapper;
    @Autowired
    EmployeeMapper employeeMapper;

    @Transactional(readOnly = true)
    @Override
    public User login(String loginName, String password) {
        return userMapper.selectByLoginNameAndPassword(loginName, password);
    }

    @Transactional(readOnly = true)
    @Override
    public List<Dept> findAllDepts() {

        return deptMapper.selectDepts();
    }
    @Transactional(readOnly = true)
    @Override
    public Dept findByDeptId(Integer deptId) {
        return deptMapper.selectById(deptId);
    }
    @Transactional(readOnly = true)
    @Override
    public List<Dept> findDeptByParams(Map<String, Object> params) {
        return deptMapper.selectByParam(params);
    }
    @Transactional(readOnly = true)
    @Override
    public List<Job> findAllJobs() {
        return jobMapper.selectJobs();
    }
    @Transactional(readOnly = true)
    @Override
    public Job findByJobId(Integer jobId) {
        return jobMapper.selectById(jobId);
    }
    @Transactional(readOnly = true)
    @Override
    public List<Job> findJobByParams(Map<String, Object> params) {
        return jobMapper.selectByParmams(params);
    }
    @Transactional(readOnly = true)
    @Override
    public List<Employee> findAllEmployees() {
        return employeeMapper.selectEmployees();
    }
    @Transactional(readOnly = true)
    @Override
    public Employee findByEmployeeId(Integer employeeId) {
        return employeeMapper.selectById(employeeId);
    }
    @Transactional(readOnly = true)
    @Override
    public List<Employee> findEmployeeByParams(Employee employee) {
        return employeeMapper.selectByparams(employee);
    }
    @Transactional(readOnly = true)
    @Override
    public List<Document> findAllDocuments() {
        return documentMapper.selectDocuments();
    }
    @Transactional(readOnly = true)
    @Override
    public Document findByDocumentId(Integer documentId) {
        return documentMapper.selectById(documentId);
    }
    @Transactional(readOnly = true)
    @Override
    public List<Document> findDocumentByParams(Document document) {
        return documentMapper.selectByParams(document);
    }
    @Transactional(readOnly = true)
    @Override
    public List<Notice> findAllNotices() {
        return noticeMapper.selectNotices();
    }
    @Transactional(readOnly = true)
    @Override
    public Notice findByNoticeId(Integer noticeId) {
        return noticeMapper.selectById(noticeId);
    }
    @Transactional(readOnly = true)
    @Override
    public List<Notice> findNoticeByParams(Notice notice) {
        return noticeMapper.selectByParams(notice);
    }
    @Transactional(readOnly = true)
    @Override
    public List<User> findAllUsers() {
        return userMapper.selectUsers();
    }
    @Transactional(readOnly = true)
    @Override
    public User findByUserId(Integer userId) {
        return userMapper.selectById(userId);
    }
    @Transactional(readOnly = true)
    @Override
    public List<User> findUserByParams(User user) {
        return userMapper.selectUserByParam(user);
    }

    @Override
    public void updateDept(Dept dept) {
        deptMapper.updateByParams(dept);
    }

    @Override
    public void updateJob(Job job, Map<String, Object> conditions) {
        jobMapper.updateByParams(job, conditions);
    }

    @Override
    public void updateDocument(Document document) {
        documentMapper.updateByParams(document);
    }

    @Override
    public void updateNotice(Notice notice) {
        noticeMapper.updateByParams(notice);
    }

    @Override
    public void updateEmployee(Employee employee) {
        employeeMapper.updateByParams(employee);
    }

    @Override
    public void updateUser(User user) {
        userMapper.updateUserByParams(user);
    }

    @Override
    public void addUser(User user) {
        userMapper.insertUser(user);
    }

    @Override
    public void addDocument(Document document) {
        documentMapper.insertByParams(document);
    }

    @Override
    public void addNotice(Notice notice) {
        noticeMapper.insertByParams(notice);
    }

    @Override
    public void addEmployee(Employee employee) {
        employeeMapper.insertByParams(employee);
    }

    @Override
    public void addDept(Dept dept) {
        deptMapper.insertByParams(dept);
    }

    @Override
    public void addJob(Job job) {
        jobMapper.insertByParams(job);
    }

    @Override
    public void deleteUser(Integer userId) {
        userMapper.deleteUserById(userId);
    }

    @Override
    public void deleteDocument(Integer documentId) {
        documentMapper.deleteById(documentId);
    }

    @Override
    public void deleteNotice(Integer noticeId) {
        noticeMapper.deleteById(noticeId);
    }

    @Override
    public void deleteDept(Integer deptId) {
        deptMapper.deleteById(deptId);
    }

    @Override
    public void deleteJob(Integer jobId) {
        jobMapper.deleteById(jobId);
    }

    @Override
    public void deleteEmployee(Integer employeeId) {
        employeeMapper.deleteById(employeeId);
    }
}
